package algorithm.sort;

public class CheckSortUtil {

    public static boolean checkSort(int[] arr, boolean asc) {
        if (arr.length < 2) {
            return true;
        }
        for (int i = 1; i < arr.length; i++) {
            int cur = arr[i];
            int pre = arr[i - 1];
            if (compare(cur,pre, asc)) {
                continue;
            }else {
                return false;
            }
        }
        return true;
    }

    private static boolean compare(int cur, int pre, boolean asc) {
        return asc ? pre < cur : pre > cur;
    }

}
